// Deck.cs created with MonoDevelop
// User: dfoelber at 00:21 07/08/2008
//
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
//

using System.Xml.Serialization;
using System.Collections.Generic;
using System;
using Xyne.CardManagement;

namespace Xyne
{
	public enum DeckShareMode
	{
		Private,
		Public
	}
	
	[XmlRoot("Deck")]
	public class Deck
	{
		private String name;
		[XmlAttribute("Name")]
		public String Name
		{
			get { return name; }
			set { name = value; }
		}
		
		private String owner;
		[XmlAttribute("Owner")]
		public String Owner
		{
			get { return owner; }
			set { owner = value; }
		}



        private Queue<CardData> cards = new Queue<CardData>();

        public Queue<CardData> GetCards()
		{
			 return cards; 
		}

        [XmlArray("Cards")]
        public CardData[] CardArray
        {
            get
            {
                return cards.ToArray();
            }

            set
            {
                cards = new Queue<CardData>(value);
            }
        }
    
		
		private DeckShareMode share;
		public DeckShareMode ShareMode
		{
			get { return share; }
			set { share = value; }
		}
		
		public Deck CreateShuffledDeck()
		{
			Deck deck = new Deck();
			deck.Name = name;			
			deck.Owner = owner;
			deck.ShareMode = share;
			
			List<CardData> tempList = new List<CardData>(cards);
			Random random = new Random((int)DateTime.Now.Ticks);
			while (tempList.Count > 0)
			{
				int index = random.Next(tempList.Count);
				deck.GetCards().Enqueue(tempList[index]);
				tempList.RemoveAt(index);
			}
			
			return deck;
		}

        public void InitCardActions()
        {
            foreach (CardData newCard in cards)
            {
                for (int i = 0; i < newCard.Actions.Count; i++)
                {
                    newCard.Actions[i].InitializeActualObjects();

                    if (newCard.Actions[i].OnCollision != null)
                        newCard.Actions[i].OnCollision.Action.InitializeActualObjects();
                }
            }
        }
	}
}
